package com.zsrt.java.day20161228.wrl.demo01;

import java.util.Arrays;

public class SelectionSort02 {
	
	public static void main(String[] args) {
		int[]	arrays = new int[]{22,55,63,45,12,46};
		System.out.println("排序前...");
		System.out.println(Arrays.toString(arrays));
		
		selectionSort(arrays);
	}
	
	/**
	 * 选择排序(从小到大):0:1,0:2,0:3,0:4 ; 
	 * 				 1:2,1:3,1:4 ; 
	 * 				 2:3,2:4 ; 
	 * 				 3:4
	 * @param arrays	原数组
	 * @return	排序后的数组
	 */
	public static void selectionSort(int[] arrays) {
		
		int length = arrays.length;
		for(int outer = 0; outer < length-1; outer++){
			for(int inner = outer+1; inner < length; inner++){
				if(arrays[outer] > arrays[inner]){
					int temp     = arrays[outer];
					arrays[outer]  = arrays[inner];
					arrays[inner]	 = temp;
				}
			}
		}
		System.out.println("排序后...");
		System.out.println(Arrays.toString(arrays));
	}

}
